import subprocess
import random
import ctypes
import platform
import sys

def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin()
    except:
        return False

# 如果当前用户不是管理员，则使用 UAC 提示框请求管理员权限
if not is_admin():
    ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
else:
    # 判断当前操作系统是否为 Windows 10
    os_version = platform.system() + ' ' + platform.release()
    if 'Windows 10' not in os_version:
        print('该脚本仅适用于 Windows 10 操作系统')
    else:
        # 设置要修改的网络接口的 MAC 地址和随机数范围
        reg_key = r"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\0003"
        min_num = 1111
        max_num = 9999

        # 生成随机 MAC 地址
        mac_address = "60AB611A"
        random_num = random.randint(min_num, max_num)
        new_mac_address = mac_address + str(random_num)

        # 使用 reg 命令设置网络接口的 MAC 地址
        subprocess.run(["reg", "add", reg_key, "/v", "NetworkAddress", "/t", "REG_SZ", "/d", new_mac_address, "/f"])

        # 使用 netsh 命令重启网络接口
        interface_name = "以太网"
        subprocess.run(["netsh", "interface", "set", "interface", interface_name, "disable"])
        subprocess.run(["netsh", "interface", "set", "interface", interface_name, "enable"])
